﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Settlements.VillageMarketData
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.Map;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Core;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Settlements
{
  public class VillageMarketData : IMarketData
  {
    [SaveableField(1)]
    private Village _village;
    private Settlement _closestTown;

    internal static void AutoGeneratedStaticCollectObjectsVillageMarketData(
      object o,
      List<object> collectedObjects)
    {
      ((VillageMarketData) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      collectedObjects.Add((object) this._village);
    }

    internal static object AutoGeneratedGetMemberValue_village(object o)
    {
      return (object) ((VillageMarketData) o)._village;
    }

    private Settlement ClosestTown
    {
      get
      {
        if (this._closestTown == null)
          this._closestTown = SettlementHelper.FindNearestTown(toMapPoint: (IMapPoint) this._village.Settlement);
        return this._closestTown;
      }
    }

    public VillageMarketData(Village village) => this._village = village;

    public int GetPrice(
      ItemObject item,
      MobileParty tradingParty,
      bool isSelling,
      PartyBase merchantParty)
    {
      return this.GetPrice(new EquipmentElement(item), tradingParty, isSelling, merchantParty);
    }

    public int GetPrice(
      EquipmentElement itemRosterElement,
      MobileParty tradingParty,
      bool isSelling,
      PartyBase merchantParty)
    {
      ItemData categoryData = (this._village.TradeBound ?? this.ClosestTown).Town.MarketData.GetCategoryData(itemRosterElement.Item.GetItemCategory());
      return Campaign.Current.Models.TradeItemPriceFactorModel.GetPrice(itemRosterElement, tradingParty, merchantParty, isSelling, (float) categoryData.InStoreValue, categoryData.Supply, categoryData.Demand);
    }
  }
}
